package com.yxjx.duoxue.audition;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.yxjx.duoxue.BaseActionBarActivity;
import com.yxjx.duoxue.Constants;
import com.yxjx.duoxue.R;
import com.yxjx.duoxue.ShareTextHelper;
import com.yxjx.duoxue.Yx;
import com.yxjx.duoxue.mta.stat.StatHelper;
import com.yxjx.duoxue.network.NwUtils;
import com.yxjx.duoxue.share.SharePopupWindow;
import com.yxjx.duoxue.utils.ShareUtils;
import com.yxjx.duoxue.utils.UIHelper;

public class ApointmentDoneActivity extends BaseActionBarActivity {
	
	private int mBookType = -1;
	private long mBookItemId = 0;
	private Context mContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_appointment_done);
		TextView part0 = (TextView) findViewById(R.id.part0);
		TextView part1 = (TextView) findViewById(R.id.part1);
		TextView part2 = (TextView) findViewById(R.id.part2);
		Bundle extra = getIntent().getExtras();
		mContext = this;
		if (extra != null) {
			// 预约内容，课程or活动
			mBookType = extra.getInt(Yx.KEY_BOOK_TYPE);
			if (mBookType == Yx.TYPE_ITEM_ACTIVITY) {
				customizeActionBarTitle("活动报名");
				part0.setText("报名完成");
			} else {
				part0.setText("预约完成");
				customizeActionBarTitle("免费预约试听");
			}
			mShareObject = extra.getSerializable(Yx.KEY_SHARE_OBJECT);
			// 预约课程or活动的id
			mBookItemId = extra.getLong(Yx.KEY_BOOK_ITEM_ID);
			part1.setText(extra.getString(ApointmentAuditionActivity.EXTRA_FIELD_1));
			part2.setText(extra.getString(ApointmentAuditionActivity.EXTRA_FIELD_2));
			
		}
		UIHelper.setClickListener(findViewById(R.id.share_button), R.id.share_button, mClickListener);

		// customize share function.
		// share activity
		String param = "id=" + mBookItemId;
		if (mBookType == Yx.TYPE_ITEM_ACTIVITY) {
			customizeShare(NwUtils.SHARE_ACTIVITY + param, mShareObject);
		} else if (mBookType == Yx.TYPE_ITEM_COURSE) {
			// share course:
			customizeShare(NwUtils.SHARE_COURSE + param, mShareObject);
		}
	}
	
	private View.OnClickListener mClickListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			switch (arg0.getId()) {
			case R.id.share:
			case R.id.share_button:
				if (mBookType == Yx.TYPE_ITEM_COURSE) {
					StatHelper.addKVEvent(mContext, "event_course_reg_share_clcik",
							StatHelper.KEY_COURSE, mBookItemId);
				}
				SharePopupWindow popup = new SharePopupWindow(ApointmentDoneActivity.this, findViewById(R.id.share));
				popup.setCallback(getShareCallback());
				break;
			default:
				mBaseClickListener.onClick(arg0);
				break;
			}
		}
	};
	private Object mShareObject;
	
	@Override
	public void onBackPressed() {
		setResult(RESULT_OK);
		super.onBackPressed();
	};
	


}
